#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include<cstdlib>
using namespace std;

class Solution {
public:
    int addDigits(int num) {
        int ans = Helper(num);
        return ans;
    }

    int Helper(int num){
        if(num < 10){
            return num;
        }
        string str = to_string(num);
        int ans = 0;
        for(int i=0;i<str.size();i++){
            ans += str[i]-'0';
        }
        ans = Helper(ans);
        return ans;
    }
};